package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ContractPrompt;
import com.ruoyi.system.domain.ContractPromptContent;
import com.ruoyi.system.service.IContractPromptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同提示词Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/contractPrompt")
public class ContractPromptController extends BaseController
{
    @Autowired
    private IContractPromptService contractPromptService;

    /**
     * 查询合同提示词列表
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractPrompt contractPrompt)
    {
        startPage();
        List<ContractPrompt> list = contractPromptService.selectContractPromptList(contractPrompt);
        return getDataTable(list);
    }

    /**
     * 导出合同提示词列表
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:export')")
    @Log(title = "合同提示词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractPrompt contractPrompt)
    {
        List<ContractPrompt> list = contractPromptService.selectContractPromptList(contractPrompt);
        ExcelUtil<ContractPrompt> util = new ExcelUtil<ContractPrompt>(ContractPrompt.class);
        util.exportExcel(response, list, "合同提示词数据");
    }

    /**
     * 获取合同提示词详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:query')")
    @GetMapping(value = "/{promptId}")
    public AjaxResult getInfo(@PathVariable("promptId") Long promptId)
    {
        return success(contractPromptService.selectContractPromptByPromptId(promptId));
    }

    /**
     * 获取合同类型关联的提示词列表
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:query')")
    @GetMapping(value = "/type/{typeId}")
    public AjaxResult getPromptsByTypeId(@PathVariable("typeId") Long typeId)
    {
        return success(contractPromptService.selectContractPromptByTypeId(typeId));
    }

    /**
     * 新增合同提示词
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:add')")
    @Log(title = "合同提示词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractPrompt contractPrompt)
    {
        return toAjax(contractPromptService.insertContractPrompt(contractPrompt));
    }

    /**
     * 修改合同提示词
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:edit')")
    @Log(title = "合同提示词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractPrompt contractPrompt)
    {
        return toAjax(contractPromptService.updateContractPrompt(contractPrompt));
    }

    /**
     * 删除合同提示词
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:remove')")
    @Log(title = "合同提示词", businessType = BusinessType.DELETE)
    @DeleteMapping("/{promptIds}")
    public AjaxResult remove(@PathVariable Long[] promptIds)
    {
        return toAjax(contractPromptService.deleteContractPromptByPromptIds(promptIds));
    }

    /**
     * 获取提示词内容
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:query')")
    @GetMapping("/content/{promptId}")
    public AjaxResult getContent(@PathVariable("promptId") Long promptId)
    {
        return success(contractPromptService.selectPromptContentByPromptId(promptId));
    }

    /**
     * 新增提示词内容
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:add')")
    @Log(title = "提示词内容", businessType = BusinessType.INSERT)
    @PostMapping("/content")
    public AjaxResult addContent(@RequestBody ContractPromptContent content)
    {
        return toAjax(contractPromptService.insertPromptContent(content));
    }

    /**
     * 修改提示词内容
     */
    @PreAuthorize("@ss.hasPermi('system:contractPrompt:edit')")
    @Log(title = "提示词内容", businessType = BusinessType.UPDATE)
    @PutMapping("/content")
    public AjaxResult editContent(@RequestBody ContractPromptContent content)
    {
        return toAjax(contractPromptService.updatePromptContent(content));
    }
}
